import java.util.Hashtable;
import java.util.StringTokenizer;
import java.util.Vector;


class P336_39643 {

       static Scanner336 scanner = new Scanner336();

       static int caseNumber = 1;

       private static Hashtable mapping;


       public static void main(String[] args) {

               int nc = scanner.getInt();

               while (nc != 0) {
                       process(nc);

                       nc = scanner.getInt();
               }

       }


       private static void process(int nc) {



               mapping = new Hashtable();

               int nodeCounter = 0;

               Vector connections = new Vector();

               for (int k = 0; k < nc; k++) {

                       int a = scanner.getInt();
                       int b = scanner.getInt();

                       if (mapping.get(new Integer(a)) == null) {
                               mapping.put(new Integer(a), new Integer(nodeCounter));
                               nodeCounter++;
                       }

                       if (mapping.get(new Integer(b)) == null) {
                               mapping.put(new Integer(b), new Integer(nodeCounter));
                               nodeCounter++;
                       }

                       int[] link = new int[2];
                       link[0] = a;
                       link[1] = b;

                       if (a != b)
                               connections.addElement(link);

               }

               int length = mapping.size();

               int[][] table = new int[length][length];

               for (int k = 0; k < length; k++) {
                       for (int j = 0; j < length; j++) {
                               table[k][j] = 4000000;
                       }
               }

               for (int k = 0; k < length; k++) {
                       table[k][k] = 0;
               }


               for (int k = 0; k < connections.size(); k++) {

                       int[] link  = (int[]) connections.elementAt(k);

                       int a = ((Integer)mapping.get(new Integer(link[0]))).intValue();
                       int b = ((Integer)mapping.get(new Integer(link[1]))).intValue();

                       table[a][b] = 1;
                       table[b][a] = 1;

               }


               for (int k = 0; k < length; k++) {
                       for (int i = 0; i < length; i++) {
                               for (int j = 0; j < length; j++) {
                                       if (table[i][j] > table[i][k] + table[k][j]) {
                                               table[i][j] = table[i][k] + table[k][j];
                                       }
                               }
                       }
               }

//              for (int[] array : table) {
//                      System.out.println(Arrays.toString(array));
//              }


               while (true) {

                       int startingNode = scanner.getInt();
                       int ttl = scanner.getInt();

                       if (startingNode == 0 && ttl == 0) break;

                       Integer i = ((Integer)mapping.get(new Integer(startingNode)));

                       int count = 0;

                       if (i == null) {
                               count = mapping.size() + 1;
                       } else {
                               count = countNodesNotVisited(table, i.intValue(), ttl);
                       }


                       System.out.println("Case " + caseNumber + ": " + count + " nodes not reachable from node " + startingNode + " with TTL = " + ttl + ".");

                       caseNumber++;
               }

       }


       private static int countNodesNotVisited(int[][] table, int i, int ttl) {

               if (ttl == 0) {
                       return mapping.size() - 1;
               }

               int count = mapping.size();

               for (int k = 0; k < table.length; k++) {
                       if (table[i][k] <= ttl) count--;
               }

               return count;
       }

}

class Scanner336 {

       StringTokenizer st = null;

       int getInt() {
               if (st == null)
                       st = new StringTokenizer(Reader336.readLn());
               while (!st.hasMoreTokens())
                       st = new StringTokenizer(Reader336.readLn());
               return Integer.parseInt(st.nextToken());
       }

}

class Reader336 {
       static String readLn() {
               String newLine = System.getProperty("line.separator");
               StringBuffer buffer = new StringBuffer();
               int car = -1;
               try {
                       car = System.in.read();
                       while ((car > 0) && (car != newLine.charAt(0))) {
                               buffer.append((char) car);
                               car = System.in.read();
                       }
                       if (car == newLine.charAt(0))
                               System.in.skip(newLine.length() - 1);
               } catch (java.io.IOException e) {
                       return (null);
               }
               if ((car < 0) && (buffer.length() == 0))
                       return (null);
               return (buffer.toString()).trim();
       }
}